package biz.datalk.industrialland.admin.modules.system.controller;

import biz.datalk.industrialland.admin.modules.system.pojo.dto.SysLoginDTO;
import biz.datalk.industrialland.admin.modules.system.service.ISysLoginService;
import biz.datalk.industrialland.common.encrypt.annotation.RSAES;
import biz.datalk.industrialland.common.log.aspect.annotation.SysLog;
import biz.datalk.industrialland.common.log.def.OptEnum;
import biz.datalk.industrialland.common.result.UnifyResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author tarofang@163.com
 * @date 2019年08月11日
 */
@RestController
@RequestMapping("/sys")
public class LoginController {

    private final ISysLoginService sysLoginService;

    @Autowired
    public LoginController(ISysLoginService sysLoginService) {
        this.sysLoginService = sysLoginService;
    }

    @RSAES
    @PostMapping(value = "/login", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @SysLog(OptEnum.LAND_LOGIN_10101)
    public UnifyResult login(@RequestBody @Validated SysLoginDTO loginDTO) {
        return sysLoginService.login(loginDTO);
    }

    @RSAES
    @PostMapping(value = "/logout", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @SysLog(OptEnum.LAND_LOGIN_10102)
    public UnifyResult logout() {
        return sysLoginService.logout();
    }

}
